import Taro , { Component } from '@tarojs/taro';
import { View, Text , Button} from '@tarojs/components';
import UserFunction from '../../components/user-function/index';
import NavigationBar from '../../components/navigationBar/index';
import { getUserInfo } from '../../services/user';
import TabBar from '../../components/tab-bar/index';
import './index.scss';


export default class Index extends Component {

   config = {
       navigationBarTitleText: '我的'
  }

  state = {
    navigationBarHeight: Taro.getStorageSync('navigationBarHeight'),
    userInfo: Taro.getStorageSync('userInfo') || null,
    statusS:5,
  }

  componentWillMount () {}
  componentDidMount () {}
  componentWillReceiveProps (nextProps,nextContext) {}
  componentWillUnmount () {}
  componentDidShow () {
     console.log(1)
    this.setState({
      userInfo: Taro.getStorageSync('userInfo') || null
    }, () => {
      if (this.state.userInfo) {
        getUserInfo({
          id: this.state.userInfo.id + ''
        }).then(res => {
          Taro.setStorageSync('userInfo', res)
          this.setState({
            userInfo: res
          })
        })
      }
    })
  }
  componentDidHide () {}
  componentDidCatchError () {}
  componentDidNotFound () {}

  render() {
    const { userInfo } = this.state;
    return (
      <View className="user" style={`margin-top: ${navigationBarHeight}`}>
        <NavigationBar text="我的"/>
        <UserFunction userInfo={userInfo} />
        <View className="tabbaruser">

          <TabBar statusS={this.state.statusS}></TabBar>
        </View>
      </View>
    );
  }
}
